package com.ruoyi.odorservice.utils;

import org.apache.commons.lang3.StringUtils;

/**
 * @author 王俊辉
 * @version 1.0
 * @date 2022/8/1 16:08
 * @description
 */
public enum ViewContentType {
    DEFAULT("default","application/octet-stream"),
    JPG("jpg", "image/jpeg"),
    TIFF("tiff", "image/tiff"),
    GIF("gif", "image/gif"),
    JFIF("jfif", "image/jpeg"),
    PNG("png", "image/png"),
    TIF("tif", "image/tiff"),
    ICO("ico", "image/x-icon"),
    JPEG("jpeg", "image/jpeg"),
    WBMP("wbmp", "image/vnd.wap.wbmp"),
    FAX("fax", "image/fax"),
    NET("net", "image/pnetvue"),
    JPE("jpe", "image/jpeg"),
    RP("rp", "image/vnd.rn-realpix"),
    WMV("wmv", "video/x-ms-wmv"),
    MP4("mp4", "video/mpeg4"),
    AVI("avi", "video/avi"),
    WMA("wma", "video/wma"),
    W4A("w4a", "video/mp4"),
    W4V("w4v", "video/mp4"),
    WOV("wov", "video/quicktime"),
    GPP("3gp", "video/3gpp"),
    MP3("mp3", "audio/mp3"),
    WEBM("webm", "video/webm"),
    FLV("flv", "video/x-flv"),
    MPEG("mpeg", "video/mpg"),
    MTS("mts", "video/vnd.dlna.mpeg-tts"),
    VOB("vob", "video/vob"),
    MKV("mkv", "video/x-matroska");
    /**
     * <uap:FileType ContentType="video/x-ms-wmv">.wmv</uap:FileType>
     * <uap:FileType ContentType="video/mpeg4">.mp4</uap:FileType>
     * <uap:FileType ContentType="video/avi">.avi</uap:FileType>
     * <uap:FileType ContentType="video/wma">.wma</uap:FileType>
     * <uap:FileType ContentType="video/mp4">.w4a</uap:FileType>
     * <uap:FileType ContentType="video/mp4">.w4v</uap:FileType>
     * <uap:FileType ContentType="video/quicktime">.wov</uap:FileType>
     * <uap:FileType ContentType="video/3gpp">.3gp</uap:FileType>
     * <uap:FileType ContentType="audio/mp3">.mp3</uap:FileType>
     * <uap:FileType ContentType="video/webm">.webm</uap:FileType>
     * <uap:FileType ContentType="video/x-flv">.flv</uap:FileType>
     * <uap:FileType ContentType="video/mpg">.mpeg</uap:FileType>
     * <uap:FileType ContentType="video/vnd.dlna.mpeg-tts">.mts</uap:FileType>
     * <uap:FileType ContentType="video/vob">.vob</uap:FileType>
     * <uap:FileType ContentType="video/x-matroska">.mkv</uap:FileType>
     */

    private String prefix;

    private String type;

    public static String getContentType(String prefix){
        if(StringUtils.isEmpty(prefix)){
            return DEFAULT.getType();
        }
        prefix = prefix.substring(prefix.lastIndexOf(".") + 1);
        for (ViewContentType value : ViewContentType.values()) {
            if(prefix.equalsIgnoreCase(value.getPrefix())){
                return value.getType();
            }
        }
        return DEFAULT.getType();
    }

    ViewContentType(String prefix, String type) {
        this.prefix = prefix;
        this.type = type;
    }

    public String getPrefix() {
        return prefix;
    }

    public String getType() {
        return type;
    }
}
